<?php
/**
 * @package Joomla
 * @subpackage Jmonoslideshow
 * @copyright (C) 2010 - Matthieu BARBE - www.ccomca.com
 * @license GNU/GPL v2
 * 
 * Jmonoslideshow is a Joomla extension for Monoslideshow.
 *
 * Jmonoslideshow uses :
 * Monoslideshow (http://www.monoslideshow.com/)
 * Plupload (http://www.plupload.com/) by Moxicode Systems
 * json class by Michal Migurski, Matt Knapp, Brett Stimmerman
 * jquery a JavaScript Library (http://jquery.com/)
 * getid3 library (http://getid3.sourceforge.net/)
 * swfobject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file (http://code.google.com/p/swfobject/)
 * Chained Selects jQuery Plugin (http://www.appelsiini.net/2010/jquery-chained-selects)
 *
 * Jmonoslideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once JPATH_ADMINISTRATOR.DS."components".DS."com_jmonoslideshow".DS.'library'.DS.'ThumbLib.inc.php';
jimport('joomla.application.component.controller');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
class JmonoslideshowControllerMedia extends JController
{
	/**
	 * Custom Constructor
	 */
	function __construct( $default = array() )
	{
		$document = & JFactory::getDocument();
		$doc = &JDocument::getInstance('raw');
		
		parent::__construct( $default );
	}
	
	/**
	* Get Media Information
	*
	* @since 2.0
	*
	*/
	
	function getMediaIntormation()
    {
		$id		= JRequest::getVar( 'id' );
		$params = &JComponentHelper::getParams( 'com_jmonoslideshow' );
		$maxThumbnailWidth = $params->get('width_vignette_hover', '400');
		$maxThumbnailHeight = $params->get( 'height_vignette_hover', '300' );
		$base_upload_dir = JPATH_ROOT.DS . 'media' . DS . 'com_jmonoslideshow' . DS . 'upload' ;
		$jpgQuality = $params->get( 'qualtiy_image', '75' );
		$options = array('jpegQuality' => $jpgQuality);
		$db = JFactory::getDbo();
		// Get the media
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from($db->nameQuote('#__monoslideshow'));
		$query->where('id = '.$db->getEscaped((int)$id) );
		$db->setQuery($query);
		$row = $db->loadAssoc();
		if ($db->getErrorNum()) 
			{
			$this->setError($db->getErrorMsg());
			return false;
			}
		
		if ($row['type'] == 0)
			{
			if ( !JFolder::exists($base_upload_dir.'/'.$maxThumbnailWidth.'-'.$maxThumbnailHeight) ) { JFolder::create($base_upload_dir.'/'.$maxThumbnailWidth.'-'.$maxThumbnailHeight); }
			if ($row['filename'])
					{
						if ( JFile::exists($base_upload_dir.'/'.$row['filename']) && !JFile::exists($base_upload_dir.'/'.$maxThumbnailWidth.'-'.$maxThumbnailHeight.'/'.$row['filename']) )
							{
								$thumb = PhpThumbFactory::create($base_upload_dir.DS.''.$row['filename'], $options);
								$thumb->resize($maxThumbnailWidth, $maxThumbnailHeight);
								$thumb->save($base_upload_dir.'/'.$maxThumbnailWidth.'-'.$maxThumbnailHeight.'/'.$row['filename']);
							}
					}
			
				echo '<img src="'.JURI::root().'media/com_jmonoslideshow/upload/'.$maxThumbnailWidth.'-'.$maxThumbnailHeight.'/'.$row['filename'].'" /> ';
			}
			else if ($row['type'] == 2)
			{
				$info = MediaHelper::info_media ($row['type'], $row['filename']);
				echo '<div class="video">'.JText::_( 'COM_JMONOSLIDESHOW_VIDEO' ).'</div>';
				echo  JText::_( 'COM_JMONOSLIDESHOW_VIDEO_TIME' ) ." : ".$info['playtime_seconds']." ".JText::_( 'COM_JMONOSLIDESHOW_SECONDS' );
				//var_dump (MediaHelper::info_media ($row['type'], $row['filename']));
			}
	}
	
	
}
